<template>
  <div class="user">
      用户模块
    <!-- 按钮 -->
    <div class="btns">
      <el-button size="small" type="warning"   @click="toAdd">添加</el-button>
      <el-button size="small" type="warning" @click="loadDate">刷新</el-button>
    </div>
    <!-- 表格 -->
    <el-table :data="list" style="width: 100%" size="small">
      <el-table-column type="index" label="序号" width="100"> </el-table-column>
      <el-table-column prop="username" label="用户名" width="100"> </el-table-column>
      <el-table-column prop="password" label="密码" width="100"> </el-table-column>
      <el-table-column prop="telephone" label="电话" width="100"> </el-table-column>
      <el-table-column prop="gender" label="性别" width="100"> </el-table-column>
      <el-table-column prop="realName" label="真实姓名" width="150"> </el-table-column>
      <el-table-column prop="photo" label="头像" width="100"> </el-table-column>
      <el-table-column prop="status" label="状态" width="100"> </el-table-column>
      <el-table-column prop="roleName" label="生肖" width="100"> </el-table-column>
        <el-table-column label="操作" width="150" align="center">
          <template v-slot="scope">
              <el-button size="small" type="text" @click="del(scope.row)">删除</el-button>
              <el-button size="small" type="text" @click="edit(scope.row)">修改</el-button>
          </template>
        </el-table-column>
    </el-table>
    <!-- 模态框 -->
    <el-dialog
    class="customer_modal"
      title="添加user"
      :visible.sync="dialogVisible"
      width="60%">


      <el-form :model="form" label-width="100px">
            <el-form-item label="用户名">
           <el-input v-model="form.username"></el-input>
            </el-form-item>

            <el-form-item label="密码">
           <el-input v-model="form.password"></el-input>
            </el-form-item>

            <el-form-item label="电话">
           <el-input v-model="form.telephone"></el-input>
            </el-form-item>
           
           <el-form-item label="性别">
                 <el-input v-model="form.gender"></el-input>
            </el-form-item>

            <el-form-item label="真实姓名">
           <el-input v-model="form.realName"></el-input>
            </el-form-item>

            <el-form-item label="头像">
           <el-input v-model="form.photo"></el-input>
            </el-form-item>

            <el-form-item label="状态">
           <el-input v-model="form.stasus"></el-input>
            </el-form-item>
            <el-form-item label="生肖">
           <el-input v-model="form.roleName"></el-input>
            </el-form-item>
      </el-form>



      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="save">保 存</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
import {get} from '@/utils/request'
export default {
  data(){
    return {
        form:{},
      list:[],
      dialogVisible:false
    }
  },
  
  created(){
      this.loadDate();
  },
  methods:{


      //保存
      save(){
          let url ="/user/saveOrUpdate";
          get(url,this.form).then((response)=>{
              this.dialogVisible=false;
              this.$message({type:"success",message:Response.message})
          this.loadDate();
          
          })
          
      },


      //删除
      del(row){
      this.$confirm('此操作将永久删除此用户, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let url = "/user/deleteById"
          get(url,{id:row.id}).then( (response)=>{
            // 1. 提示
            this.$message({type:"success",message:response.message})
            // 2. 刷新 
            this.loadData();
          } )
        })
    },

      edit(row){
         this.form=row;
         this.dialogVisible=true;
      },
      loadDate(){
          let url="/user/findAllWithRole";
          get(url).then((Response)=>{
              this.list=Response.data;
          })

      },
    toAdd(){
      this.dialogVisible = true;
    }
  }
}</script>